/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-07-31 00:54:18
 * @LastEditors: paddies
 * @LastEditTime: 2024-07-31 03:26:04
 * @FilePath: /shared_components/lib/build-page/buildPage.dart
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_components/build-common/buildCommon.dart';

Widget buildPage(
    {bool centerTitle = true,
    String title = "标题",
    int activeTab = 0, //默认选中第一个
    bool hasTab = true, //是否有tab栏
    List tabList = const [],
    Widget? navSlot,
    bool hasNavBody = true}) {
  var _activeColor = const Color(0xff0000f5);
  var _activeTab = 0.obs;
  _activeTab.value = activeTab;
  return Obx(() => Scaffold(
      appBar: AppBar(
        centerTitle: centerTitle,
        scrolledUnderElevation: 0.0,
        iconTheme: const IconThemeData(
          color: Colors.black, //修改颜色
        ),
        title: Text(
          title,
          style: const TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.white,
      ),
      backgroundColor: const Color(0xfff6f6f6),
      body: SizedBox(
        width: double.infinity,
        height: double.infinity,
        child: Column(
          children: [
            //有 tab
            Visibility(
                visible: hasTab,
                child: Expanded(
                  child: Container(
                    width: double.infinity,
                    height: double.infinity,
                    color: Colors.yellow,
                    child: Column(children: [
                      Container(
                          width: double.infinity,
                          height: 60,
                          color: Colors.white,
                          child: Row(
                            children: tabList.asMap().keys.map((index) {
                              var fontColor = const Color(0xff666666);
                              if (_activeTab.value == index) {
                                fontColor = _activeColor;
                              }
                              return Expanded(
                                  child: Stack(
                                      alignment: Alignment.center,
                                      children: [
                                    Container(
                                      height: double.infinity,
                                      // color: Colors.red,
                                      width: 70,
                                      child: GestureDetector(
                                          onTap: () {
                                            _activeTab.value = index;
                                            // controller.changeTab(index: index);
                                          },
                                          child: Container(
                                            alignment: Alignment.center,
                                            width: double.infinity,
                                            height: double.infinity,
                                            color: Colors.transparent,
                                            child: Stack(
                                              alignment: Alignment.center,
                                              children: [
                                                Text(
                                                  showText(tabList[index]
                                                      .value["name"]),
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: fontColor,
                                                      fontWeight:
                                                          FontWeight.w500),
                                                ),
                                                if (_activeTab.value == index)
                                                  Container(
                                                    margin:
                                                        const EdgeInsets.only(
                                                            top: 40),
                                                    width: 30,
                                                    height: 5,
                                                    decoration: BoxDecoration(
                                                        borderRadius:
                                                            BorderRadius.all(
                                                                Radius.circular(
                                                                    20.0)), //圆角
                                                        gradient:
                                                            LinearGradient(
                                                                begin: Alignment
                                                                    .topLeft, //渐变开始于上面的中间开始
                                                                end: Alignment.topRight, //渐变结束于下面的中间
                                                                colors: [
                                                              _activeColor,
                                                              _activeColor
                                                            ] //开始颜色和结束颜色])),
                                                                )),
                                                  )
                                              ],
                                            ),
                                          )),
                                    ),
                                  ]
                                      // children:
                                      ));
                            }).toList(),
                          )),
                      Expanded(
                          child: Container(
                              width: double.infinity,
                              height: double.infinity,
                              color: Colors.green,
                              child: Column(
                                children: [
                                  ...(tabList[_activeTab.value]["list"] as List)
                                      .map((e) {
                                    return Text("111");
                                  }).toList()
                                ],
                              )
                              // Text(showText(tabList[_activeTab.value]["list"])),
                              ))
                    ]),
                  ),
                )),

            Visibility(
                visible: !hasTab,
                child: Expanded(
                  child: SizedBox(
                    width: double.infinity,
                    height: double.infinity,
                    child: RefreshIndicator(
                        onRefresh: () async {},
                        child: Container(
                            width: double.infinity,
                            height: double.infinity,
                            color: Colors.red,
                            child: SingleChildScrollView(
                              physics: AlwaysScrollableScrollPhysics(),
                              // controller: scrollController,
                              // child: ,
                            ))),
                  ),
                ))
            // navSlot ?? const SizedBox(),
          ],
        ),
      )));
}

List getShowItem() {
  var res = [];
  return [];
}

getList() {}
